using UnityEngine;

public class ArmJointFix : MonoBehaviour
{
	public GameObject upperArm;

	public GameObject lowerArm;

	public HingeJoint2D lowerArmJoint;

	public PlayerBody playerBody;

	public TargetJoint2D helperJoint;

	public float upperArmRotationMax;

	public float upperArmRotationMin;

	public float upperArmRotation;

	public float lowerArmRotation;

	public bool invoked;

	private void FixedUpdate()
	{
		if (!IsGood() && !invoked)
		{
			invoked = true;
			Invoke("Fix", 0.05f);
		}
	}

	public void Fix()
	{
		if (!IsGood())
		{
			upperArm.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, upperArmRotation));
			lowerArm.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, lowerArmRotation));
		}
		invoked = false;
	}

	public bool IsGood()
	{
		if (!playerBody.player.isDead && (lowerArmJoint.jointAngle > lowerArmJoint.limits.max || lowerArmJoint.jointAngle < lowerArmJoint.limits.min) && upperArm.transform.localEulerAngles.z > upperArmRotationMax && upperArm.transform.localEulerAngles.z < upperArmRotationMin && (!playerBody.player.weapon || !playerBody.player.weapon.onReload))
		{
			if ((bool)playerBody.player.placingTool)
			{
				return playerBody.player.placingTool.onPlace;
			}
			return false;
		}
		return true;
	}
}
